from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *

import password_managment
from try_mysql import *
from PyQt5.uic import loadUiType
from cinema import Cinema_App
from register import Register_App
import password_managment
from movie_record_manage_ui import Ui_Movie_record
import sys
ui, _ = loadUiType('begin.ui')

class Begin_App(QMainWindow, ui):
    #定义构造
    def __init__(self):
        QMainWindow.__init__(self)
        self.setupUi(self)
        self.handle_buttons()
        self.menubar.setObjectName("menubar")
        self.menuHelp.setObjectName("menuHelp")
        self.login.setObjectName("login")
        self.exitlogin.setObjectName("exitlogin")
        self.actionexit.setObjectName("actionexit")
        self.actionxiugaimima.setObjectName("actionxiugaimima")
        self.login.setEnabled(False)
        self.exitlogin.setEnabled(False)
        self.actionexit.setEnabled(True)
        self.actionxiugaimima.setEnabled(True)
        self.menuHelp.triggered[QAction].connect(self.menuTriggered)
        self.lineEdit_2.setEchoMode(QLineEdit.Password)


    def handle_buttons(self):
        self.begin_login.clicked.connect(self.UserLogin)
        self.begin_regist.clicked.connect(self.UserRegister)


    def UserLogin(self):
        conn = get_conn()
        cur = conn.cursor()
        StaffNum=self.begin_staff_num.text()
        StaffPassword=self.lineEdit_2.text()
        if (StaffNum==""or StaffPassword==""):
            self.statusBar().showMessage('员工号和密码不得为空')
            return
        else:
            sql2 = "select * from user where StaffNum=%s and StaffPassword=%s "
            cur.execute(sql2, (StaffNum, StaffPassword))
            data = cur.fetchone()
            if data:
                self.Mainwindow = Cinema_App()
                return
            else:
                self.statusBar().showMessage('请输入正确的密码或者员工号')

    def UserRegister(self):
        self.Mainwindow = Register_App()

    def menuTriggered(self, q):
        if (q.text()=="修改密码"):
            self.change_password_app=password_managment.Password_App()
            self.change_password_app.show()

        if (q.text() == "退出"):
            qApp = QApplication.instance()
            qApp.quit()
        return

def main():
    app = QApplication([])
    window = Begin_App()
    window.show()
    app.exec_()

if __name__ == '__main__':
    main()


